#include "..\include\NewUserDlg.h"

//(*InternalHeaders(CNewUserDlg)
#include <wx/xrc/xmlres.h>
//*)

//(*IdInit(CNewUserDlg)
//*)

BEGIN_EVENT_TABLE(CNewUserDlg,wxDialog)
	//(*EventTable(CNewUserDlg)
	//*)
END_EVENT_TABLE()

CNewUserDlg::CNewUserDlg(wxWindow* parent, SUserInfo& UI, bool& RememberMe)
{
	//(*Initialize(CNewUserDlg)
	wxXmlResource::Get()->LoadObject(this,parent,_T("CNewUserDlg"),_T("wxDialog"));
	StaticText1 = (wxStaticText*)FindWindow(XRCID("ID_STATICTEXT1"));
	StaticText2 = (wxStaticText*)FindWindow(XRCID("ID_STATICTEXT2"));
	TextCtrl1 = (wxTextCtrl*)FindWindow(XRCID("ID_FIRSTNAMECTRL"));
	StaticText3 = (wxStaticText*)FindWindow(XRCID("ID_STATICTEXT3"));
	TextCtrl2 = (wxTextCtrl*)FindWindow(XRCID("ID_LASTNAMECTRL"));
	StaticText4 = (wxStaticText*)FindWindow(XRCID("ID_STATICTEXT4"));
	TextCtrl3 = (wxTextCtrl*)FindWindow(XRCID("ID_USERNAMECTRL"));
	StaticText5 = (wxStaticText*)FindWindow(XRCID("ID_STATICTEXT5"));
	TextCtrl4 = (wxTextCtrl*)FindWindow(XRCID("ID_PASSWORD1CTRL"));
	StaticText6 = (wxStaticText*)FindWindow(XRCID("ID_STATICTEXT6"));
	TextCtrl5 = (wxTextCtrl*)FindWindow(XRCID("ID_PASSWORD2CTRL"));
	StaticLine1 = (wxStaticLine*)FindWindow(XRCID("ID_STATICLINE1"));
	CheckBox1 = (wxCheckBox*)FindWindow(XRCID("ID_CHECKBOX1"));
	Button1 = (wxButton*)FindWindow(XRCID("ID_BTNOK"));
	Button2 = (wxButton*)FindWindow(XRCID("ID_BTNCANCEL"));
	//*)

	// set validators
	m_pFirstNameCtrl->SetValidator(wxTextValidator(wxFILTER_NONE, &UI.FirstName) );
	m_pLastNameCtrl->SetValidator(wxTextValidator(wxFILTER_NONE, &UI.LastName) );
	m_pUserNameCtrl->SetValidator(wxTextValidator(wxFILTER_NONE, &UI.UserName) );
	m_pPassword1Ctrl->SetValidator(wxTextValidator(wxFILTER_NONE, &UI.Password) );
	m_pCheckBox1->SetValidator(wxGenericValidator(&RememberMe) );
}

CNewUserDlg::~CNewUserDlg()
{
	//(*Destroy(CNewUserDlg)
	//*)
}


void CNewUserDlg::OnBtnOKClick(wxCommandEvent& event)
{
    if (m_pPassword1Ctrl->GetLabelText() != m_pPassword2Ctrl->GetLabelText() )
    {
        mmMessageDlg(this, _("Password MisMatch") );
        return;
    }
    if (Validate() && TransferDataFromWindow() )
    {
        if (IsModal() )
            EndModal(wxID_OK);
        else
        {
            SetReturnCode(wxID_OK);
            this->Show(false);
        }
    }
}

void CNewUserDlg::OnBtnCancelClick(wxCommandEvent& event)
{
    if (IsModal() )
        EndModal(wxID_CANCEL);
    else
    {
        SetReturnCode(wxID_CANCEL);
        this->Show(false);
    }
}
